<!--营销管理-->
<template>
  <div class="main">
    <div class="info-container" v-loading="loading">
      <div class="info-container_body">
        <el-form ref="refFrom" label-position="top" class="demo">
          <el-form-item label="投放openId">
            <el-input v-model="currentItem.openId" />
          </el-form-item>
          <el-form-item label="投放张数">
            <el-input-number v-model="currentItem.number" />
          </el-form-item>

          <el-row>
            <el-col :span="12">
              <el-form-item label="活动类型">
                {{marchType(item.coupon.couponType,type)}}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="活动名称">
                {{item.activityName}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24" v-if="item.activityType == '2'">
              <el-form-item label="积分比例">
                {{item.points.exchangeRate}}
              </el-form-item>
            </el-col>
            <el-col :span="24" v-else-if="item.coupon.couponType == '1'">
              <el-form-item label="优惠金额(元)" v-if="item.coupon.optionsBo.cash.cashType=='1'">
                {{item.coupon.optionsBo.cash.denomination}}
              </el-form-item>
              <el-form-item label="优惠金额(元)" v-else-if="item.coupon.optionsBo.cash.cashType=='2'">
                {{item.coupon.optionsBo.cash.randomFloorAmount}}-{{item.coupon.optionsBo.cash.randomRoofAmount}}
              </el-form-item>
            </el-col>
            <el-col :span="24" v-else-if="item.coupon.couponType == '2'">
              <el-form-item label="满减条件">
                <span v-for="(discount,index) in item.coupon.optionsBo.discounts" :key="index">
                  &nbsp;{{index>0?"/":""}} 满{{discount.minOrderAmount}}元减{{discount.discountAmount}}元
                </span>
              </el-form-item>
            </el-col>
            <el-col :span="24" v-else-if="item.coupon.couponType == '3'">
              <el-form-item label="体验时长（分钟）">
                {{item.coupon.optionsBo.experience.durationMs}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12"
              ><el-form-item label="发放总张数">
                {{item.coupon.totalQuantity}}
              </el-form-item></el-col
            >
            <el-col :span="12">
              <el-form-item label="同账号可领取张数">
                {{item.coupon.claimCount}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="可用对象">
                {{marchType(item.scope,scope)}}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="可用范围">
                {{marchType(item.orderType,orderType)}}
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="发放比例">{{item.coupon.distributionRatio}}% </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="活动时间起止"> {{ item.startTime }}-{{ item.endTime }} </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item label="券有效期时间起止"> {{item.coupon.validFrom}}-{{item.coupon.validTo}} </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
      <div class="info-container_footer">
        <el-button @click="handleCancel">取消</el-button>
        <el-button type="primary" @click="handleSave">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { getActivity, targeted } from '@/api/operation/activity/index';
import common from '@/utils/common.ts';

export default {
  props: {
    data: {}
  },
  data() {
    return {
      currentItem: {
        openId: null,
        activityId: '',
        number: 1
      },
      item: {
        regions: [],
        time: [],
        valids: [],

        createDept: 0,
        createBy: 0,
        createTime: '',
        updateBy: 0,
        updateTime: '',
        params: {
          property1: {},
          property2: {}
        },
        activityType: '1',
        scope: '',
        orderType: '',
        activityName: '',
        activityDescription: '',
        startTime: '',
        endTime: '',
        orderAmount: 0,
        qrCode: '',
        status: '',
        coupon: {
          createDept: 0,
          createBy: 0,
          createTime: '',
          updateBy: 0,
          updateTime: '',
          params: {
            property1: {},
            property2: {}
          },
          activityId: 0,
          couponType: '',
          validFrom: '',
          validTo: '',
          distributionRatio: 0,
          claimCount: 0,
          totalQuantity: 0,
          participantsQuantity: 0,
          collectedQuantity: 0,
          verifiedQuantity: 0,
          optionsBo: {
            experience: {
              durationMs: 0
            },
            discounts: [
              {
                minOrderAmount: 0,
                discountAmount: 0
              }
            ],
            cash: {
              cashType: '',
              denomination: 0,
              randomFloorAmount: 0,
              randomRoofAmount: 0
            }
          },
          redemptionPeriod: 60,
          options: ''
        },
        points: {
          createDept: 0,
          createBy: 0,
          createTime: '',
          updateBy: 0,
          updateTime: '',
          params: {
            property1: {},
            property2: {}
          },
          activityId: 0,
          exchangeRate: 0,
          discountRate: 0
        },
        activityVendors: [
          {
            createDept: 0,
            createBy: 0,
            createTime: '',
            updateBy: 0,
            updateTime: '',
            params: {
              property1: {},
              property2: {}
            },
            id: 0,
            activityId: 0,
            vendorId: 0
          }
        ],
        activityRegions: [
          {
            createDept: 0,
            createBy: 0,
            createTime: '',
            updateBy: 0,
            updateTime: '',
            params: {
              property1: {},
              property2: {}
            },
            id: 0,
            activityId: 0,
            regionCode: ''
          }
        ]
      },
      loading: false,
      type: [
        { label: '优惠', value: '1' },
        { label: '积分', value: '0' },
        { label: '满减', value: '2' },
        { label: '体验', value: '3' }
      ],
      couponType: [
        { label: '定额', value: '1' },
        { label: '随机', value: '2' }
      ],
      scope: [
        { label: '全局', value: 1 },
        { label: '区域', value: 2 },
        { label: '酒店', value: 3 }
      ],
      orderType: [
        { label: '全局', value: '1' },
        { label: '吸氧', value: '2' },
        { label: '充灌', value: '3' }
      ]
    };
  },
  created() {
    this.init();
  },
  methods: {
    init() {
      let id = this.data.activityId;
      this.currentItem.activityId = id;

      if (id == null) {
      } else {
        getActivity(id).then((res) => {
          let data = res.data;
          data = common.operActivity.verifyDataIntegrity(this.item, data);
          console.log(data);
          this.item = data;
        });
      }
    },

    handleSave() {
      this.loading = true;
      targeted(this.currentItem)
        .then((res) => {
          this.loading = false;
          if (res.code == 200) {
            //todo:
            this.$emit('hideRight');
          } else {
            ElMessage.error(res.msg);
          }
        })
        .catch(() => {
          this.loading = false;
        });
    },
    handleCancel() {
      this.$emit('hideRight');
    },
    /**
     * 匹配结果
     */
    marchType(value, types) {
      for (let i = 0; i < types.length; i++) {
        let type = types[i];
        if (type.value == value) return type.label;
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.main {
  height: 100%;
  .contentFrm {
    padding: 10px;
    background: #f6f7fb;
  }

  .el-input-number__decrease,
  .el-input-number__increase {
    display: none;
  }

  .el-input-number {
    width: 100%;
  }
}
</style>
